<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<head>
    <th:block th:include="include :: header('公文详情')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
    <th:block th:include="include :: summernote-css" />
</head>

<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-arrange-edit" th:object="${documentArrange}">
            <input id="userIds" name="userIds" th:field="*{userIds}" class="form-control" type="hidden">
            <input name="arrangeId" th:field="*{arrangeId}" class="form-control" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">公文标题：</label>
                <div class="col-sm-8">
                    <input name="arrangeTitle" th:field="*{arrangeTitle}" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">重要程度：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('document_importance')}">
                        <input type="radio" th:id="${'documentImportance_' + dict.dictCode}" name="documentImportance"
                            th:value="${dict.dictValue}" th:checked="*{documentImportance}" disabled>
                        <label th:for="${'documentImportance_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">发布范围：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <span class="input-group-addon"><a onclick="javaScript:chooseAllUser();">全员</a></span>
                        <span class="input-group-addon"><a onclick="javaScript:chooseUser();">选择</a></span>
                        <input id="releaseScope" name="releaseScope" th:field="*{releaseScope}" class="form-control" type="text" disabled>
                        <span class="input-group-addon"><a onclick="javaScript:clearUser();">清空</a></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">参与人数：</label>
                <div class="col-sm-8">
                    <input id="total" name="total" th:field="*{total}" class="form-control" type="number" unselectable="on" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">开始日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="startDate" class="form-control" placeholder="格式：yyyy-MM-dd" type="text"
                            th:value="*{#dates.format(startDate, 'yyyy-MM-dd')}" disabled>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">结束日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="endDate" class="form-control" placeholder="格式：yyyy-MM-dd" type="text"
                            th:value="*{#dates.format(endDate, 'yyyy-MM-dd')}" disabled>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">站内提示：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('is_tips')}">
                        <input type="radio" th:id="${'websiteTips_' + dict.dictCode}" name="websiteTips"
                            th:value="${dict.dictValue}" th:field="*{websiteTips}" disabled>
                        <label th:for="${'websiteTips_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">短信提示：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('is_tips')}">
                        <input type="radio" th:id="${'smsTips_' + dict.dictCode}" name="smsTips"
                            th:value="${dict.dictValue}" th:field="*{smsTips}" disabled>
                        <label th:for="${'smsTips_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">附件：</label>
                <div class="col-sm-8">
                    <input id="attachments" name="attachments" th:value="*{attachments}" type="hidden">
                    <div class="file-loading">
                        <input id="file-upload" name="file" class="form-control file-upload" type="file" multiple>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label" disabled>公文内容：</label>
                <div class="col-sm-8">
                    <input id="documentContent" name="documentContent" th:field="*{documentContent}" class="form-control" type="hidden">
                    <div id="content" class="summernote"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control" disabled>[[*{remark}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "document/arrange"
        var statusDatas = [[${@dict.getType('document_progress_status') }]];

        $(function() {
		    $('.summernote').summernote({
		    	placeholder: '请输入公文内容',
		    	height : 192,
				lang : 'zh-CN',
				followingToolbar: false,
				callbacks: {
	                onImageUpload: function (files) {
	                    sendFile(files[0], this);
	                }
	            }
		    });
            var content = $("#documentContent").val();
		    $('#content').summernote('code', content);
	    });

        // 编辑器上传文件
        function sendFile(file, obj) {
            var data = new FormData();
            data.append("file", file);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function (result) {
                    if (result.code == web_status.SUCCESS) {
                        $(obj).summernote('editor.insertImage', result.url, result.fileName);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function (error) {
                    $.modal.alertWarning("图片上传失败。");
                }
            });
        }

        // 附件上传初始化
        $(function(){
            initUploadFileInfo("attachments", "file-upload", [], "");
        })        

        $("#form-arrange-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            var sHTML = $('.summernote').summernote('code');
            $("#documentContent").val(sHTML);
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-arrange-edit').serialize());
            }
        }

        $("input[name='startDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='endDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        function chooseAllUser() {
            $("#releaseScope").val(page_constants.ALL_USER)
            $.ajax({
                type: "POST",
                url: ctx + "common/activeUserCount",
                error: function (request) {
                    $.modal.alertError("系统错误");
                },
                success: function (data) {
                    $("#total").val(data.data);
                }
            });
        }

        function chooseUser() {
            $.modal.open("选择用户", ctx + "common/chooseUser");
        }

        function clearUser() {
            $("#releaseScope").val("");
            $("#total").val(0);
        }
    </script>
</body>

</html>